package com.abel.roommanager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.abel.roommanager.pojo.Landlord;
import com.abel.roommanager.pojo.Room;
import com.abel.roommanager.service.RoomService;
import com.abel.roommanager.util.Page;
@Controller
@RequestMapping("/room")
@Scope("prototype")
public class RoomContrller {
	@Resource
	private RoomService roomService;
	@RequestMapping("/findEnableLive")
	@ResponseBody
   public List<Room> findEnableRoom() {
	return roomService.findAllRoom();	
}
	@RequestMapping("/findAll")
	@ResponseBody
   public List<Room> findAllRoom() {
	return roomService.findRooms();	
}
	@RequestMapping("/findRoomsBySid")
	@ResponseBody
	public List<Room> findRoomsBySid(int id) {
		return roomService.findRoomsBySid(id);
		
	}
	//分页查询所有房间信息
	@RequestMapping("/findRoomsByCurpage")
	@ResponseBody
	public Page<Room> findAllRoomByCurpage(int curPage) {
		return roomService.findRoomsByCurpage(curPage);
		
	}
	@RequestMapping("/add")
	@ResponseBody
	public int addRoom(Room room,Landlord landlord) {
		return roomService.addRoom(room,landlord);
		
	}
	@RequestMapping(value="/del",method=RequestMethod.POST)
	@ResponseBody
	public int delRoom(int id) {
		return roomService.delRoom(id);
		
	}
	@RequestMapping("/findRoomById")
	public ModelAndView findRoomById(int id){
		ModelAndView modelAndView=new ModelAndView("/jsp/room-info.jsp");
		Room room=roomService.findRoomInfoById(id);
		modelAndView.addObject("roomInfo", room);
		return modelAndView;
	}
	@RequestMapping("/findRoomsByLimits")
	@ResponseBody
	public Page<Room> findRoomsByLimits(Room room,int enableLiving,int curPage){
		String address=room.getAddress();
		address="%"+address+"%";
		room.setAddress(address);
		return roomService.findRoomsByLimits(room,enableLiving,curPage);
	}
	@RequestMapping("/findRoomsBySex")
	@ResponseBody
	public List<Room> findRoomsBySex(int sex) {
		return roomService.findRoomsBySex(sex);
		
	}
}
